package com.dc.bobaoge.project.v2.to.v3.business.core;

import com.dc.bobaoge.base.entity.message.common.po.MessageComplaint;
import com.dc.bobaoge.base.mapper.message.MessageComplaintMapper;
import com.dc.bobaoge.project.base.core.now.mapper.CustomMessageComplaintMapper;
import com.dc.bobaoge.project.base.core.old.mapper.OldCoreMessageReportMapper;
import com.dc.bobaoge.project.base.core.util.MessageCommonUtil;
import com.dc.bobaoge.project.v2.to.v3.business.core.method.user.UserResolveMethod;
import com.own.business.sync.trigger.base.entity.SyncTrigger;
import com.own.business.sync.trigger.base.method.ResolveMethod;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * MessageComplaintResolveMethod
 *
 * @author chenxueli
 * @date 2023-12-22 19:49:00
 */
@Slf4j
@Component
public class MessageComplaintResolveMethod implements ResolveMethod {

    @Resource
    private MessageComplaintMapper messageComplaintMapper;

    @Resource
    private CustomMessageComplaintMapper customMessageComplaintMapper;
    @Resource
    private OldCoreMessageReportMapper oldCoreMessageReportMapper;

    @Resource
    private UserResolveMethod userResolveMethod;

    @Resource
    private MessageCommonUtil messageCommonUtil;

    /**
     * 修改的处理方法
     *
     * @param trigger 日志信息
     */
    @Override
    public void update(SyncTrigger trigger) {
        // 删除已有的信息
        customMessageComplaintMapper.delete(trigger.getTargetId());
        // 查询举报信息
        var complaint = oldCoreMessageReportMapper.selectById(trigger.getTargetId());
        if (complaint == null) {
            throw new RuntimeException("举报不存在: " + trigger.getTargetId());
        }
        // 查询信息的基础信息
        var baseInfo = messageCommonUtil.getSimple(complaint.getReportMsgId());
        // 查询评论的用户信息
        var user = userResolveMethod.getByUserId(complaint.getReportUserId());
        var messageComplaint = new MessageComplaint();
        messageComplaint.setId(complaint.getReportId());
        messageComplaint.setFkMessageId(complaint.getReportMsgId());
        messageComplaint.setComplaintTime(complaint.getReportTime());
        messageComplaint.setContent(complaint.getReportContent());
        messageComplaint.setFkUserId(baseInfo.getUserId());
        messageComplaint.setConcatPhone(user.value1().getPhone());
        messageComplaint.setConcatUserId(user.value2().getId());
        messageComplaint.setConcatUserName(user.value1().getName());
        messageComplaint.setStatus(1);
        // 保存
        messageComplaintMapper.insert(messageComplaint);
    }

    /**
     * 删除的处理方法
     *
     * @param trigger 日志信息
     */
    @Override
    public void delete(SyncTrigger trigger) {
        messageComplaintMapper.deleteById(trigger.getTargetId());
    }

    /**
     * 名称信息
     *
     * @return 名称
     */
    @Override
    public String name() {
        return "message_complaint";
    }

}
